****************************************************************
**** 		Figure 4 - Treatment Effects of Interim Payment Cash Infusion on Worker Productivity
****************************************************************


use "$dir/Data/analysis_main.dta", clear


** Event study graph by wealth 


cap drop *_hiw
foreach y of varlist pre_announce_3_cash pre_announce_2_cash post_cash_1 post_cash_2 post_cash_3 post_cash_4_plus pre_announce_3 pre_announce_2 post_pay_1 post_pay_2 post_pay_3 post_pay_4_plus papc papc_cash{
	gen `y'_hiw = wealth_hi_avg*`y'
}

reghdfe n_productivity pre_announce_3_cash pre_announce_2_cash post_cash_1 post_cash_2 post_cash_3 post_cash_4_plus pre_announce_3 pre_announce_2 post_pay_1 post_pay_2 post_pay_3 post_pay_4_plus ///
	papc papc_cash *_hiw , absorb(pid day) vce(cluster pid)

cap drop xval_cash* coef_cash* se_cash* uconf_cash* lconf_cash*
gen xval_cash1 = _n + 0.1 if _n<8
gen xval_cash2 = _n - 0.1 if _n<8
gen coef_cash1 = .
gen coef_cash2 = .
replace coef_cash1 = 0 if _n==3
replace coef_cash2 = 0 if _n==3
gen se_cash1 = .
gen se_cash2 = .

local i=0
foreach x in pre_announce_3_cash pre_announce_2_cash {
	local `i++'
	replace coef_cash1 = _b[`x'] if _n==`i' 
	replace se_cash1 = _se[`x'] if _n==`i' 
	replace coef_cash2 = _b[`x'_hiw] + _b[`x'] if _n==`i'
	lincom _b[`x'_hiw] + _b[`x']
	replace se_cash2 = r(se) if _n==`i'
}

local i=3
foreach x in post_cash_1 post_cash_2 post_cash_3 post_cash_4_plus {
	local `i++'
	replace coef_cash1 = _b[`x'] if _n==`i' 
	replace se_cash1 = _se[`x'] if _n==`i' 
	replace coef_cash2 = _b[`x'_hiw] + _b[`x'] if _n==`i'
	lincom _b[`x'_hiw] + _b[`x']
	replace se_cash2 = r(se) if _n==`i'
}

gen uconf_cash1 = coef_cash1 + 1.645*se_cash1
gen lconf_cash1 = coef_cash1 - 1.645*se_cash1
gen uconf_cash2 = coef_cash2 + 1.645*se_cash2
gen lconf_cash2 = coef_cash2 - 1.645*se_cash2



twoway (scatter coef_cash1 xval_cash1 , msymbol(T) msize(medium) mcolor("100 149 237") ) ///
       (rcap uconf_cash1 lconf_cash1 xval_cash1, color("100 149 237")) ///
	   (scatter coef_cash2 xval_cash2 , msymbol(O) msize(medium) mcolor("255 127 80") ) ///
       (rcap uconf_cash2 lconf_cash2 xval_cash2, color("255 127 80")) ///
	   , graphregion(color(white) margin(b+1)) yscale(range(-0.3 0.4) titlegap(*10)) ylabel(#6) yline(0, lpattern(solid) lcolor(gs12) lwidth(medthin)) ytitle("Productivity (SDs)") /// 
	   xscale(range(0.5 6.5) titlegap(*10)) xline(3.5, lpattern(shortdash) lcolor(black)) xlabel(1 "Day -3" 2 "Day -2" 3 "Day -1" 4 "Day 1" 5 "Day 2" 6 "Day 3" 7 "Day 4+", nogrid) xtitle("") ///
		b2title("{bf:Baseline                                              Post-payment}") legend(on order(1 "Lower wealth" 3 "Higher wealth") position(11) row(2) ring(0) region(lcolor(white)) bmargin(5 0 0 3))

graph export "$om/$f/Figure_4.eps", replace
graph export "$om/$f/Figure_4.png", replace

